<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建材料价格库</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>分类</label>
                        <div class="layui-input-block">
                            <div id="basetype_cai"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">施工地点</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="xiangtype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">签约年度</label>
                        <div class="layui-input-block">
                            <input type="text" name="shidt" id="shidt" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">供货方式</label>
                        <div class="layui-input-block">
                            <div id="gongtype_cai"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">材料品牌或厂商</label>
                        <div class="layui-input-block">
                            <input type="text" name="painame" id="painame" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>材料名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="pinname" id="pinname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">规格型号</label>
                        <div class="layui-input-block">
                            <input type="text" name="guige" id="guige" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计量单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="valunit" id="valunit" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>不含税单价</label>
                        <div class="layui-input-block">
                            <input type="text" name="noratefee" id="noratefee" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">价格日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="pridt" id="pridt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">供货负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongname" id="gongname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongtel" id="gongtel" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注1</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注2</label>
                        <div class="layui-input-block">
                            <textarea id="explaintwo" name="explaintwo" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_isku = getQueryVariable('isku') || 0;
    var param_ku_index = getQueryVariable('ku_index') || 0;

    $("#commentForm").validate({
        rules: {
            pinname: {required: true},
            noratefee: {required: true},
        },
        messages:{
            pinname: {required: "请输入"},
            noratefee: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_main_base_cai_add}).done(function(res){
            if (res.code === 2000) {

                if(param_isku > 0){
                    $("#name").val(parent.engininfo.name);
                    $("#areas").val(parent.engininfo.areas);
                    xmselect_dan('xiangtype', res.data.xiangtype, parent.engininfo.xiangtype);
                    $("#pinname").val($("#list_list tr", parent.document).eq(param_ku_index).find('.name').val());
                    $("#guige").val($("#list_list tr", parent.document).eq(param_ku_index).find('.guige').val());
                    $("#valunit").val($("#list_list tr", parent.document).eq(param_ku_index).find('.valunit').val());
                    $("#noratefee").val($("#list_list tr", parent.document).eq(param_ku_index).find('.no_price').val());
                    $("#explain").val('清单入库');
                }else{
                    xmselect_dan('xiangtype', res.data.xiangtype, '');
                }

                xmselect_dan('basetype_cai', res.data.basetype_cai, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#basetype_cai").find('xm-select').removeClass('error');
                    }else{
                        $("#basetype_cai").find('xm-select').addClass('error');
                    }
                });


                xmselect_dan('gongtype_cai', res.data.gongtype_cai, '');

                load_areas('areas', res.data.areas, 3);

                initParseMoney();
                public_upload_file_load('upload_files');
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            if(!data.field.basetype_cai){
                $("#basetype_cai").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#basetype_cai").find('xm-select').removeClass('error');
            }

            if(!validRes){return false;}


            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_main_base_cai_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    if(param_isku > 0){
                        facade.success("提交成功!");
                        $("#list_list tr", parent.document).eq(param_ku_index).find('.name').attr('source',res.data.id);
                        $("#list_list tr", parent.document).eq(param_ku_index).find('.opt_ru').addClass('layui-hide');
                        $("#list_list tr", parent.document).eq(param_ku_index).find('.opt_cha').removeClass('layui-hide');
                        $("#list_list tr", parent.document).eq(param_ku_index).find('.opt_qing').removeClass('layui-hide');
                        setTimeout(() => {
                            layer_close_opt();
                        }, 1500);
                    }else{
                        dataPostTimeOut();
                    }
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
